﻿@page "/admin/data-dictionary"
@attribute [Authorize(BXJGUtilsConsts.GeneralTreeMenuName)]
@inherits AdminGeneralTreeListBaseComponent< Create,DetailOrUpdate, IDataDictionaryAppService, GeneralTreeDto, GeneralTreeEditDto, GeneralTreeEditDto, GeneralTreeGetTreeInput>

<MudStack Style="height:100%;" onclick="@HideDeleteConfirm">
    <MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center">
        <MudButtonGroup OverrideStyles="false">
            @if (isCreateGranted)
            {
                <MudButton OnClick="BtnAddClick" Variant="Variant.Filled" StartIcon="@Icons.Material.Outlined.Add" Color="Color.Primary">新增</MudButton>
            }
            @*@if (updateIsGranted)
            {
            <MudButton OnClick="()=>EditClick()" Disabled="!ShouldEnableEdit" Variant="Variant.Filled" StartIcon="@Icons.Material.Outlined.Edit" Color="Color.Default">修改</MudButton>
            }*@
            @if (isDeleteGranted)
            {
                <MudButton OnClick="ShowDeleteConfirm" Disabled="IsDisableDelete" Variant="Variant.Filled" Color="Color.Warning">
                    @if (isDeleting)
                    {
                        <MudProgressCircular Color="Color.Surface" Size="Size.Small" Indeterminate="true" />
                        <MudText class="ml-1">正在删除...</MudText>
                    }
                    else
                    {
                        <MudIcon Icon="@Icons.Material.Outlined.Delete" Size="Size.Small" />
                        <MudText Class="ml-1">删除</MudText>
                    }
                    <MudPopover Open="isShowDeleteConfirm" Fixed="true" Class="pa-3" AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
                        <MudStack>
                            <MudAlert Severity="Severity.Warning">确定删除已选择的数据吗？</MudAlert>
                            <MudStack Row="true" Justify="Justify.Center">
                                <MudButton OnClick="BtnDeleteClick" Size="Size.Small" Variant="Variant.Filled" Color="Color.Error">删除</MudButton>
                                <MudButton OnClick="HideDeleteConfirm" Size="Size.Small" Variant="Variant.Filled" Color="Color.Default">取消</MudButton>
                            </MudStack>
                        </MudStack>
                    </MudPopover>
                </MudButton>
            }
        </MudButtonGroup>

        @* 直接给搜索框赋值宽度时，搜索框不会被顶到最右边
        <div style="width:18rem;">
        <MudTextField T="string"
        Margin="Margin.Dense"
        Variant="Variant.Outlined"
        Placeholder="输入关键字后回车"
        Adornment="Adornment.Start"
        Style="background-color:white;"
        TextChanged="KeywordsChanged"
        AdornmentIcon="@Icons.Material.Outlined.Search"
        Clearable="true"></MudTextField>
        </div>
        *@
        <MudButtonGroup OverrideStyles="false">
            <MudIconButton OnClick="()=>Reload()" Variant="Variant.Filled" Icon="@Icons.Material.Outlined.Refresh" />
        </MudButtonGroup>
    </MudStack>

    <MudPaper Class="py-1 pr-1">
        @if (isLoadingTops)
        {
            <MudProgressLinear Color="Color.Primary" Indeterminate="true"  />
        }
        else
        {
            <MudTreeView Hover="true"
            @ref="mudTreeView"
                              Width="100%" Dense="true"
                         Items="tops"
                         ServerData="Load"
                              MultiSelection="true"
            @bind-ActivatedValue="activatedValue"
            @bind-SelectedValues="selected"
                              ExpandOnDoubleClick="true">
                <ItemTemplate>
                    <MudTreeViewItem Value="context" Text="@context.DisplayName" CanExpand="context.ChildrenCount>0" OnClick="@HideDeleteConfirm" @ref="(context as IExtendableDto).ExtensionData.Control">
                        <BodyContent Context="item">
                            <MudStack Row="true" Justify="Justify.SpaceBetween" AlignItems="AlignItems.Center" Style="width:100%;" Class="py-1" >
                                <MudText Style="justify-self: start; width:20rem;">@context.DisplayName</MudText>
                                @if (context.IsSysDefine)
                                {
                                    <MudText>系统预设</MudText>
                                }
                                <MudButtonGroup OverrideStyles="false">
                                    <MudButton StartIcon="@Icons.Material.Filled.Info" Size="Size.Small" Variant="Variant.Outlined" Color="Color.Primary" OnClick="()=>BtnDetailClick(context)">详情</MudButton>
                                    @if (isUpdateGranted)
                                    {
                                        <MudButton StartIcon="@Icons.Material.Filled.Edit" Size="Size.Small" Variant="Variant.Outlined" OnClick="()=>BtnEditClick(context)">修改</MudButton>
                                    }
                                    @if (!context.IsSysDefine && isDeleteGranted)
                                    {
                                        <MudButton OnClick="()=>ShowDeleteItemConfirm(context)" Size="Size.Small" Variant="Variant.Outlined" Color="Color.Warning">
                                            @if ((context as IExtendableDto).ExtensionData.IsDeleting)
                                            {
                                                <MudProgressCircular Color="Color.Surface" Size="Size.Small" Indeterminate="true" />
                                                <MudText class="ml-1">正在删除...</MudText>
                                            }
                                            else
                                            {
                                                <MudIcon Icon="@Icons.Material.Outlined.Delete" Size="Size.Small" />
                                                <MudText Class="ml-1">删除</MudText>
                                            }
                                            <MudPopover Open="(context as IExtendableDto).ExtensionData.IsShowDeleteConfirmation" Fixed="true" Class="pa-3" AnchorOrigin="Origin.BottomCenter" TransformOrigin="Origin.TopCenter">
                                                <MudStack>
                                                    <MudAlert Severity="Severity.Warning">确定删除已选择的数据吗？</MudAlert>
                                                    <MudStack Row="true" Justify="Justify.Center">
                                                        <MudButton OnClick="()=>BtnDeleteItemClick(context)" Size="Size.Small" Variant="Variant.Filled" Color="Color.Error">删除</MudButton>
                                                        <MudButton OnClick="HideDeleteConfirm" Size="Size.Small" Variant="Variant.Filled" Color="Color.Default">取消</MudButton>
                                                    </MudStack>
                                                </MudStack>
                                            </MudPopover>
                                        </MudButton>
                                    }
                                    <MudIconButton OnClick="()=>Reload(context)" Icon="@Icons.Material.Filled.Refresh" Size="Size.Small" Variant="Variant.Outlined" />
                                </MudButtonGroup>
                            </MudStack>
                        </BodyContent>
                    </MudTreeViewItem>
                </ItemTemplate>
            </MudTreeView>
        }

    </MudPaper>
</MudStack>